/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


import worker from '@ohos.worker'; // 导入worker模块
import http from '@ohos.net.http';
import hilog from '@ohos.hilog';

export async function get100kFile() {
  let httpRequest = http.createHttp()
  httpRequest.request(
    "XXX",
    {
      method: http.RequestMethod.GET, // 可选，默认为http.RequestMethod.GET
      connectTimeout: 5000, // 可选，默认为60s
      readTimeout: 5000, // 可选，默认为60s
    }, (err, data) => {
    if (!err) {
      // @ts-ignore
      let s: String = String.fromCharCode.apply(null, new Uint8Array(data.result));
      s.length
      return 0 // 8+
    } else {
      httpRequest.destroy();
      return 0
    }
  }
  )
  return 0
}


var parentPort = worker.workerPort; // 获取parentPort属性
// 接收宿主线程的数据
parentPort.onmessage = async function (e) { // 定义onmessage方法
  let data = e.data
  hilog.info(0X0000, "TAOBAO", "tao bao on message Data get100kFile" + JSON.stringify(data))
  const newData = await get100kFile()
  parentPort.postMessage(newData) // 返回值
}
